home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 3 / Gold Medal Software - Volume 3 (Gold Medal) (1994).iso / os2 / cenv2_19.arj / SESSION.CMD < prev    next >
OS/2 REXX Batch file  |  1994-03-11  |  23KB  |  628 lines

  1. EXTPROC CEnvi
  2. //************************************************************************
  3. //*** Session.cmd - Allow to start any type of session at any location ***
  4. //*** ver.2         with any title and position.  Etc...  This could   ***
  5. //***               be used in place of OS/2's START command.  And it  ***
  6. //***               runs much quicker if you /BIND it.                 ***
  7. //************************************************************************
  8.  
  9. // This is a list of Default DOS settings, change to what you like.  If
  10. // left commented out then will retain system default.  Any values set
  11. // here will be overwritten by value input at command line.  For those
  12. // options where many text strings are avaialable, remove comments from
  13. // ONE AND ONLY ONE of the choices
  14.  
  15. MyDefaultDOSSettings = {
  16.    "COM_DIRECT_ACCESS=0",  // 0 or 1
  17.    "COM_HOLD=0",           // 0 or 1
  18.    "COM_RECEIVE_BUFFER_FLUSH="   // select one of the following
  19.       //"ALL",
  20.       //"RECEIVE DATA INTERRUPT ENABLE",
  21.       //"SWITCH TO FOREGROUND",
  22.       "NONE",
  23.    "COM_SELECT="
  24.       " ALL",
  25.       //"COM1",
  26.       //"COM2",
  27.       //"COM3",
  28.       //"COM4",
  29.       //"NONE",
  30.    "DOS_AUTOEXEC=C:\\AUTOEXEC.BAT",
  31.    "DOS_BACKGROUND_EXECUTION=1", // 0 or 1
  32.    "DOS_BREAK=1", // 0 or 1
  33.    "DOS_DEVICE=SIZE=0  C:\\OS2\\MDOS\\ANSI.SYS",
  34.    "DOS_FCBS=16",
  35.    "DOS_FCBS_KEEP=8",
  36.    "DOS_FILES=75",
  37.    "DOS_HIGH=0",  // 0 or 1
  38.    "DOS_LASTDRIVE=Z",
  39.    "DOS_RMSIZE=640",
  40.    "DOS_SHELL=C:\\OS2\\MDOS\\COMMAND.COM C:\\OS2\\MDOS",
  41.    "DOS_UMB=0",   // 0 or 1
  42.    "DOS_VERSION=DCJSS02.EXE,3,40,255"
  43.       "\nDFIA0MOD.SYS,3,40,255"
  44.       "\nDXMA0MOD.SYS,3,40,255"
  45.       "\nEXCEL.EXE,10,10,4"
  46.       "\nIBMCACHE.COM,3,40,255"
  47.       "\nIBMCACHE.SYS,3,40,255"
  48.       "\nISAM.EXE,3,40,255"
  49.       "\nISAM2.EXE,3,40,255"
  50.       "\nISQL.EXE,3,40,255"
  51.       "\nMSD.EXE,5,00,255"
  52.       "\nNET3.COM,3,40,255"
  53.       "\nNETX.COM,4,00,255"
  54.       "\nNETX.EXE,5,00,255"
  55.       "\nPSCPG.COM,3,40,255"
  56.       "\nSAF.EXE,3,40,255"
  57.       "\nWIN200.BIN,10,10,4",
  58.    "DPMI_DOS_API="   // select one of the following
  59.       "AUTO",
  60.       //"ENABLED",
  61.       //"DISABLED",
  62.    "DPMI_MEMORY_LIMIT=4",
  63.    "DPMI_NETWORK_BUFF_SIZE=8",
  64.    "EMS_FRAME_LOCATION="
  65.       "AUTO",
  66.       //"NONE",
  67.       //"C000",
  68.       //"C400",
  69.       //"C800",
  70.       //"CC00",
  71.       //"D000",
  72.       //"D400",
  73.       //"D800",
  74.       //"DC00",
  75.       //"8000",
  76.       //"8400",
  77.       //"8800",
  78.       //"8C00",
  79.       //"9000",
  80.    "EMS_HIGH_OS_MAP_REGION=0",
  81.    "EMS_LOW_OS_MAP_REGION=384",
  82.    "EMS_MEMORY_LIMIT=2048",
  83.    "HW_NOSOUND=0",      // 0 or 1
  84.    "HW_ROM_TO_RAM=0",   // 0 or 1
  85.    "HW_TIMER=0",        // 0 or 1
  86.    "IDLE_SECONDS=0",
  87.    "IDLE_SENSITIVITY=75",
  88.    "INT_DURING_IO=0",   // 0 or 1
  89.    "KBD_ALTHOME_BYPASS=0", // 0 or 1
  90.    "KBD_BUFFER_EXTEND=1",  // 0 or 1
  91.    "KBD_CTRL_BYPASS="   // select one of the following
  92.       "NONE",
  93.       //"ALT_ESC",
  94.       //"CTRL_ESC",
  95.    "KBD_RATE_LOCK=0",   // 0 or 1
  96.    "MEM_EXCLUDE_REGIONS=",
  97.    "MEM_INCLUDE_REGIONS=",
  98.    "MOUSE_EXCLUSIVE_ACCESS=0",   // 0 or 1
  99.    "PRINT_SEPARATE_OUTPUT=1",    // 0 or 1
  100.    "PRINT_TIMEOUT=15",
  101.    "VIDEO_8514A_XGA_IOTRAP=1",   // 0 or 1
  102.    "VIDEO_FASTPASTE=0",          // 0 or 1
  103.    "VIDEO_MODE_RESTRICTION="  // select one of the following
  104.       "NONE         ",
  105.       //"CGA            ",
  106.       //"MONO           ",
  107.    "VIDEO_ONDEMAND_MEMORY=1",    // 0 or 1
  108.    "VIDEO_RETRACE_EMULATION=1",  // 0 or 1
  109.    "VIDEO_ROM_EMULATION=1",      // 0 or 1
  110.    "VIDEO_SWITCH_NOTIFICATION=0",// 0 or 1
  111.    "VIDEO_WINDOW_REFRESH=1",
  112.    "XMS_HANDLES=32",
  113.    "XMS_MEMORY_LIMIT=2048",
  114.    "XMS_MINIMUM_HMA=0"
  115. };
  116.  
  117. #define WINDOWS_EXECUTABLE    "WINOS2.COM"
  118. #define DEFAULT_WINDOWS_PROG  "PROGMAN.EXE"
  119. #define INTERVAL_BETWEEN_LOOKS   300   // how long to wait between checking if
  120.                                        // window exists yet
  121. #define MAXIMUM_LOOKS_FOR_WINDOW 50    // after looking 80 times for window,
  122.                                        // then give up
  123. #define WAIT_INTERVAL            1500  // how many milliseconds (approx.) to
  124.                                        // wait between checking if session has
  125.                                        // ended; if /WAIT specified
  126.  
  127. #include <OptParms.lib>    // for parsing command-line parameters
  128. #include <Profile.lib>     // for getting and setting font size
  129. #include <PMdll.lib>       // used by WinTools.lib
  130. #include <WinTools.lib>    // adjust window size and position
  131.  
  132. main(argc,argv)
  133. {
  134.    if ( argc == 1
  135.      || OptionalParameter(argc,argv,"?")
  136.      || OptionalParameter(argc,argv,"help")
  137.      || OptionalParameter(argc,argv,"h") ) {
  138.       Instructions();
  139.       success = False;
  140.    } else {
  141.       ParseInputParameters(argc,argv);
  142.       StartData = BuildStartData();
  143.  
  144.       if ( Background )
  145.          RememberActiveWindow = GetActiveWindow();
  146.  
  147.       if ( SetFont ) {
  148.          GetCharacterFont(SaveWidth,SaveHeight);
  149.          SetCharacterFont(FontX,FontY);
  150.       }
  151.  
  152.       success = StartSession(StartData);
  153.  
  154.       if ( SetFont )
  155.          SetCharacterFont(SaveWidth,SaveHeight);
  156.  
  157.       if ( success  && ( AdjustWindowAfterCreation || MustWait || TitleSupplied ) ) {
  158.          // StartSession attempted to set these window settings, but
  159.          // it probably failed.  If we can find the window Title
  160.          // now, then use that window handle to set these things.
  161.          if ( NULL == ( WinHandle = FindWindowHandle(Title,OldWindowList) ) ) {
  162.             printf("\n\aUnable to locate \"%s\"\n",Title);
  163.             success = False;
  164.          } else if ( AdjustWindowAfterCreation ) {
  165.             AdjustWindow(WinHandle);
  166.          }
  167.       }
  168.  
  169.       if ( Background )
  170.          SetActiveWindow(RememberActiveWindow);
  171.  
  172.       if ( success && MustWait ) {
  173.          // hang around until WinHandle is no longer valid
  174.          do {
  175.             suspend(WAIT_INTERVAL);
  176.          } while ( IsWindow(WinHandle) );
  177.       }
  178.  
  179.    }
  180.    return success ? EXIT_SUCCESS : EXIT_FAILURE ;
  181. }
  182.  
  183. ForeGround, BackGround;
  184. Title; TitleSupplied;
  185. InheritConfigSysEnvironment;
  186. FullScreen, Windowed, PresentationManager, DOSApplication;
  187. Windows, Enhanced, Separate;
  188. IconFile;
  189. Hidden, Maximized, Minimized, WantBig, Keep, MustWait;
  190. WantSetPosition, PosX, PosY;
  191. WantSetSize, SizeX, SizeY;
  192. SetFont, FontX, FontY;
  193. UseDosSettings;
  194. ProgramName, ProgramInputs;
  195. AdjustWindowAfterCreation;
  196. #define ERROR_BUFFER_SIZE  300
  197. ErrorBuffer[0] = ErrorBuffer[ERROR_BUFFER_SIZE+1] = '\0';
  198.  
  199. ParseInputParameters(argc,argv)
  200. {
  201.    ForeGround = OptionalParameter(argc,argv,"F");
  202.    BackGround = OptionalParameter(argc,argv,"B");
  203.    Title = NULL; TitleSupplied = OptionalParameter(argc,argv,"TITLE",Title);
  204.    InheritConfigSysEnvironment = OptionalParameter(argc,argv,"I");
  205.    FullScreen = OptionalParameter(argc,argv,"FS");
  206.    Windowed = OptionalParameter(argc,argv,"WIN");
  207.    PresentationManager = OptionalParameter(argc,argv,"PM");
  208.    DosApplication = OptionalParameter(argc,argv,"DOS");
  209.    Enhanced = OptionalParameter(argc,argv,"ENH");
  210.    Separate = OptionalParameter(argc,argv,"SEP");
  211.    Windows = OptionalParameter(argc,argv,"W")
  212.           || Separate || Enhanced ;
  213.    IconFile = NULL; OptionalParameter(argc,argv,"ICON",IconFile);
  214.    Hidden = OptionalParameter(argc,argv,"HID");
  215.    Maximized = OptionalParameter(argc,argv,"MAX");
  216.    Minimized = OptionalParameter(argc,argv,"MIN");
  217.    WantBig = OptionalParameter(argc,argv,"BIG");
  218.    Keep = OptionalParameter(argc,argv,"K");
  219.    MustWait = OptionalParameter(argc,argv,"WAIT");
  220.    WantSetPosition = ( OptionalParameter(argc,argv,"POS",string)
  221.                   && ScanfRowCol(string,PosX,PosY) );
  222.    WantSetSize = ( OptionalParameter(argc,argv,"SIZE",string)
  223.                 && ScanfRowCol(string,SizeX,SizeY) );
  224.    SetFont = ( OptionalParameter(argc,argv,"FONT",string)
  225.             && ScanfRowCol(string,FontY,FontX) );
  226.    UseDosSettings = DosApplication || Windows;
  227.    while ( OptionalParameter(argc,argv,"SET",string) ) {
  228.       UseDosSettings = True;
  229.       switch ( string[0] ) {
  230.          case '@':
  231.             GetSettingsFromFile(string+1);
  232.             break;
  233.          case '#':
  234.             GetSettingsFromEnvironmentVariable(string+1);
  235.             break;
  236.          default:
  237.             AddNewSetting(string);
  238.             break;
  239.       }
  240.    }
  241.  
  242.    AdjustWindowAfterCreation = ( ForeGround & !Windows )
  243.                             || Hidden || Maximized || WantBig
  244.                             || Minimized|| WantSetPosition || WantSetSize ;
  245.  
  246.    // any further arguments are the ProgramName and ProgramInputs
  247.    ProgramName = (argc == 1) ? NULL : argv[1] ;
  248.    if ( argc < 3 ) {
  249.       ProgramInputs = NULL;
  250.    } else {
  251.       // build program input string of all further arguments together
  252.       strcpy(ProgramInputs,argv[2]);
  253.       for ( i = 3; i < argc; i++ ) {
  254.          strcat(ProgramInputs," ");
  255.          strcat(ProgramInputs,argv[i]);
  256.       }
  257.    }
  258.  
  259.    if ( Windows ) {
  260.       // Windows needs a default program, so use Program Manager
  261.       if ( NULL == ProgramName )
  262.          ProgramName = DEFAULT_WINDOWS_PROG;
  263.    }
  264.  
  265.    if ( !Title ) {
  266.       // YUCK!!! No one likes a session with no title. So give it one.
  267.       // Title will be all but path of ProgramName.  But if no program
  268.       // name then will match the sesion type.
  269.       if ( ProgramName != NULL ) {
  270.          strcpy(Title,ProgramName + strlen(SplitFileName(ProgramName).dir));
  271.       }
  272.       if ( !Title || !Title[0] ) {
  273.          // Get name from session type
  274.          if ( UseDosSettings ) Title = "DOS Session";
  275.          else if ( Windows ) Title = "Windows Session";
  276.          else if ( PresentationManager ) Title = "PM Session";
  277.          else Title = "Session";
  278.       }
  279.    }
  280.  
  281. }
  282.  
  283. ScanfRowCol(string,Row,Col)  // scan ROWxCOL or ROWXCOL or ROWxCOL, or return FALSE
  284. {
  285.    return( 2 == sscanf(string,"%dx%d",Row,Col)
  286.         || 2 == sscanf(string,"%dX%d",Row,Col)
  287.         || 2 == sscanf(string,"%d,%d",Row,Col) );
  288. }
  289.  
  290. MyDefaultDOSSettings;
  291.  
  292. AddNewSetting(setting)
  293.    // add setting string to MyDefaultDOSSettings, or replace one that is
  294.    // already there if it has the same "NAME=VALUE" name
  295. {
  296.    // Find the length of variable name: all characters before '='
  297.    VarLen = strcspn(setting,"=");
  298.    if ( 0 == VarLen  ||  strlen(setting) == VarLen ) {
  299.       printf("\n\aInvalid setting \"%s\" ignored.",setting);
  300.       printf("\nPress any key to continue...");
  301.       getch();
  302.       printf("\n");
  303.    } else {
  304.       SettingIndex = 0;
  305.       if ( defined(MyDefaultDOSSettings) ) {
  306.          // check existing settings if this is already in the list
  307.          MaxSettingIndex = GetArraySpan(MyDefaultDOSSettings);
  308.          for( ; SettingIndex <= MaxSettingIndex; SettingIndex++ ) {
  309.             if ( !memicmp(MyDefaultDOSSettings[SettingIndex],setting,
  310.                           VarLen+1) )
  311.                break;
  312.          }
  313.       }
  314.       strcpy(MyDefaultDOSSettings[SettingIndex],setting);
  315.    }
  316. }
  317.  
  318. GetSettingsFromFile(FileName)
  319.    // read in each setting line from file, and add to DOS settings
  320. {
  321.    fp = fopen(FileName,"r");
  322.    if ( NULL == fp ) {
  323.       printf("\n\aUnable to open settings file \"%s\"",FileName);
  324.       printf("\nPress any key to continue...");
  325.       getch();
  326.       printf("\n");
  327.    } else {
  328.       while ( NULL != (setting = fgets(fp)) ) {
  329.          if ( '\n' == setting[len = strlen(setting) - 1] )
  330.             setting[len] = 0;
  331.          if ( ';' != setting[0]  &  '\0' != setting[0] )
  332.             AddNewSetting(setting);
  333.       }
  334.       fclose(fp);
  335.    }
  336. }
  337.  
  338. GetSettingsFromEnvironmentVariable(evar)
  339.    // get settings from environment variable, if there is one.  Individual
  340.    // setting statements are separated by semi-colons
  341. {
  342.    if ( NULL != (string = getenv(evar)) ) {
  343.       for ( NextString = strtok(string,";");
  344.             NULL != NextString; NextString = strtok(NULL,";") ) {
  345.          if ( NULL != (EqualPosition = strchr(NextString,',')) ) {
  346.             EqualPosition[0] = '=';
  347.             AddNewSetting(NextString);
  348.          }
  349.       }
  350.    }
  351. }
  352.  
  353. DetermineSessionType()
  354.    // return integer representing the TYPE of session to start
  355. {
  356.    #define SESSION_DEFAULT             0
  357.    #define SESSION_OS2_FULLSCREEN      1
  358.    #define SESSION_WINDOWABLEVIO       2
  359.    #define SESSION_PM                  3
  360.    #define SESSION_DOS_FULLSCREEN      4
  361.    #define SESSION_DOS_WINDOWED        7
  362.    #define SESSION_WIN_STD_SEPARATE    15
  363.    #define SESSION_WIN_STD             16
  364.    #define SESSION_WIN_ENH_SEPARATE    17
  365.    #define SESSION_WIN_ENH             18
  366.    #define SESSION_WIN_ENH_FULLSCREEN  19
  367.    #define SESSION_WIN_STD_FULLSCREEN  20
  368.  
  369.    #define PROG_DEFAULT             (PROGCATEGORY)0
  370.    #define PROG_FULLSCREEN          (PROGCATEGORY)1
  371.    #define PROG_WINDOWABLEVIO       (PROGCATEGORY)2
  372.    #define PROG_PM                  (PROGCATEGORY)3
  373.    #define PROG_GROUP               (PROGCATEGORY)5
  374.    #define PROG_REAL                (PROGCATEGORY)4
  375.    #define PROG_VDM                 (PROGCATEGORY)4
  376.    #define PROG_WINDOWEDVDM         (PROGCATEGORY)7
  377.    #define PROG_DLL                 (PROGCATEGORY)6
  378.    #define PROG_PDD                 (PROGCATEGORY)8
  379.    #define PROG_VDD                 (PROGCATEGORY)9
  380.    #define PROG_WINDOW_REAL         (PROGCATEGORY)10
  381.    #define PROG_WINDOW_PROT         (PROGCATEGORY)11
  382.    #define PROG_WINDOW_AUTO         (PROGCATEGORY)12
  383.    #define PROG_SEAMLESSVDM         (PROGCATEGORY)13
  384.    #define PROG_SEAMLESSCOMMON      (PROGCATEGORY)14
  385.    #define PROG_RESERVED            (PROGCATEGORY)255
  386.  
  387.    if ( PresentationManager ) return SESSION_PM;
  388.    if ( Windows ) {
  389.       if ( Separate )
  390.          return Enhanced ? SESSION_WIN_ENH_SEPARATE : SESSION_WIN_STD_SEPARATE;
  391.       if ( FullScreen )
  392.          // return Enhanced ? SESSION_WIN_ENH_FULLSCREEN : SESSION_WIN_STD_FULLSCREEN;
  393.          return SESSION_DOS_FULLSCREEN;
  394.       return Enhanced ? SESSION_WIN_ENH : SESSION_WIN_STD;
  395.    }
  396.    if ( UseDosSettings ) {
  397.       return ( Windowed && !FullScreen )
  398.            ? SESSION_DOS_WINDOWED : SESSION_DOS_FULLSCREEN ;
  399.    }
  400.    if ( FullScreen ) return SESSION_OS2_FULLSCREEN;
  401.    if ( Windowed ) return SESSION_WINDOWABLEVIO;
  402.    return SESSION_DEFAULT;
  403. }
  404.  
  405. GetDOSSettingsString()
  406.    // return MyDefaultDOSSettings() array as a large string where each
  407.    // element is separaterd by a NULL byte
  408. {
  409.    string = SettingString = "";
  410.    count = GetArraySpan(setting = MyDefaultDOSSettings);
  411.    while( 0 <= count-- ) {
  412.       strcpy(string,setting[0]);
  413.       string += strlen(string) + 1;
  414.       setting++;
  415.    }
  416.    string[0] = '\0';
  417.    return SettingString;
  418. }
  419.  
  420.  
  421. PgmName, PgmInputs, env; // globals used in following function
  422. BuildStartData()
  423.    // Build the StartData structure (BLOb) based on the global data already
  424.    // retrieved.  Return the blob
  425. {
  426.    BLObPut(data,0,UWORD16); // size of block; we'll get back to this
  427.       #define SSF_RELATED_INDEPENDENT 0
  428.       #define SSF_RELATED_CHILD       1
  429.    BLObPut(data,SSF_RELATED_INDEPENDENT,UWORD16);
  430.       #define SSF_FGBG_FORE   0
  431.       #define SSF_FGBG_BACK   1
  432.    BLObPut(data,ForeGround ? SSF_FGBG_FORE : SSF_FGBG_BACK,UWORD16);
  433.       #define SSF_TRACEOPT_NONE       0
  434.       #define SSF_TRACEOPT_TRACE      1
  435.       #define SSF_TRACEOPT_TRACEALL   2
  436.    BLObPut(data,SSF_TRACEOPT_NONE,UWORD16);
  437.    if ( Windows  &&  NULL != Title && !Fullscreen ) {
  438.       sprintf(Title-8,"Session:%s",Title);
  439.       BLObPut(data,pointer(Title)-8,UWORD32);
  440.    }
  441.    else
  442.       BLObPut(data,Title ? pointer(Title) : NULL,UWORD32);
  443.  
  444.    // Preform a cheat here with the ProgramName and inputs so that
  445.    // windows programs will be started by WINOS2.COM and be set
  446.    // to enhanced mode if that is wanted
  447.    if ( Windows ) {
  448.       PgmName = WINDOWS_EXECUTABLE;
  449.       if ( NULL == ProgramInputs )
  450.          PgmInputs = ProgramName;
  451.       else
  452.          sprintf(PgmInputs,"%s %s",ProgramName,ProgramInputs);
  453.       if ( Enhanced ) {
  454.          // Add /3 to parameters to start in enhanced mode
  455.          if ( NULL == PgmInputs )
  456.             PgmInputs = "/3";
  457.          else
  458.             sprintf(PgmInputs,"/3 %s",PgmInputs);
  459.       }
  460.    } else {
  461.       PgmName = ProgramName;
  462.       PgmInputs = ProgramInputs;
  463.    }
  464.  
  465.    BLObPut(data,PgmName ? pointer(PgmName) : NULL,UWORD32);
  466.    BLObPut(data,PgmInputs ? pointer(PgmInputs) : NULL,UWORD32);
  467.  
  468.    BLObPut(data,NULL,UWORD32);  // no termination queue
  469.    if ( UseDosSettings  &&  defined(MyDefaultDOSSettings) ) {
  470.       env = GetDOSSettingsString();
  471.       BLObPut(data,pointer(env),UWORD32);
  472.    } else {
  473.       BLObPut(data,NULL,UWORD32);  // no environment setting
  474.    }
  475.       #define SSF_INHERTOPT_SHELL     0
  476.       #define SSF_INHERTOPT_PARENT    1   // for DOS session, inherit drive and directory
  477.    BLObPut( data,
  478.             InheritConfigSysEnvironment ? SSF_INHERTOPT_SHELL : SSF_INHERTOPT_PARENT,
  479.             UWORD16 );
  480.    BLObPut(data,DetermineSessionType(),UWORD16);
  481.    BLObPut(data,IconFile ? pointer(IconFile) : NULL,UWORD32);
  482.    BLObPut(data,NULL,UWORD32);  // no program handle
  483.  
  484.    #define SSF_CONTROL_VISIBLE     0x0000
  485.    #define SSF_CONTROL_INVISIBLE   0x0001
  486.    #define SSF_CONTROL_MAXIMIZE    0x0002
  487.    #define SSF_CONTROL_MINIMIZE    0x0004
  488.    #define SSF_CONTROL_NOAUTOCLOSE 0x0008
  489.    #define SSF_CONTROL_SETPOS      0x8000
  490.    PgmControl = 0;
  491.    if ( Hidden ) PgmControl |= SSF_CONTROL_INVISIBLE;
  492.    if ( Maximized ) PgmControl |= SSF_CONTROL_MAXIMIZE;
  493.    if ( Minimized ) PgmControl |= SSF_CONTROL_MINIMIZE;
  494.    if ( Keep ) PgmControl |= SSF_CONTROL_NOAUTOCLOSE;
  495.    if ( WantSetPosition || WantSetSize ) PgmControl |= SSF_CONTROL_SETPOS;
  496.    BLObPut(data,PgmControl,UWORD16);
  497.  
  498.    if ( !WantSetPosition ) PosX = PosY = 0;
  499.    if ( !WantSetSize ) SizeX = SizeY = 0;
  500.    BLObPut(data,PosX,SWORD16);
  501.    BLObPut(data,PosY,SWORD16);
  502.    BLObPut(data,SizeX,SWORD16);
  503.    BLObPut(data,SizeY,SWORD16);
  504.    BLObPut(data,0,SWORD16);      // reserved byte; required
  505.  
  506.    BLObPut(data,pointer(ErrorBuffer),UWORD32);
  507.    BLObPut(data,ERROR_BUFFER_SIZE,UWORD32);
  508.  
  509.    BLObPut(data,0,BLObSize(data),UWORD16); // size of block
  510.    return data;
  511. }
  512.  
  513. StartSession(StartData)
  514.    // call OS/2 start session functions
  515. {
  516.    #define ORD_DOS32STARTSESSION 37
  517.    rc = DynamicLink("SESMGR",ORD_DOS32STARTSESSION,BIT32,CDECL,
  518.                     StartData,DummySessionID,DummyProcessID);
  519.  
  520.    #define ERROR_SMG_START_IN_BACKGROUND   457
  521.    if ( rc  &&  ERROR_SMG_START_IN_BACKGROUND != rc ) {
  522.       printf("Error %d starting session\a\a\n",rc);
  523.       if ( 0 < strlen(ErrorBuffer) )
  524.          printf("Error in object: %s\n",ErrorBuffer);
  525.       return(False);
  526.    }
  527.    return(True);
  528. }
  529.  
  530. GetCharacterFont(FontWidth,FontHeight)
  531. {
  532.    // Get current size
  533.    BLObSize(current,2);
  534.    PrfQueryProfileData(HINI_USERPROFILE,"Shield","~Font Size...",current,2);
  535.    FontHeight = BLObGet(current,1,UWORD8);
  536.    FontWidth = BLObGet(current,0,UWORD8);
  537. }
  538.  
  539. SetCharacterFont(FontWidth,FontHeight)
  540. {
  541.    BLObPut(new,0,FontWidth,UWORD8);
  542.    BLObPut(new,1,FontHeight,UWORD8);
  543.    PrfWriteProfileData(HINI_USERPROFILE,"Shield","~Font Size...",new,2);
  544. }
  545.  
  546. FindWindowHandle(WindowTitle,OldWindowList)
  547.    // Wait around for a while for a new window with this WindowTitle.
  548.    // return NULL if not found
  549. {
  550.    for ( retry = MAXIMUM_LOOKS_FOR_WINDOW; retry;
  551.          retry--, suspend(INTERVAL_BETWEEN_LOOKS) ) {
  552.       if ( NULL != (NewHandle = GetWindowHandle(WindowTitle)) )
  553.          return(NewHandle);
  554.    }
  555.    return(NULL);
  556. }
  557.  
  558. AdjustWindow(hwnd)
  559. {
  560.    if ( WantBig || Maximized ) {
  561.       ShowWindow(hwnd,ForeGround ? SW_SHOWMAXIMIZED : SW_SHOWMAXNOACTIVE);
  562.       if ( WantBig ) {
  563.          // get maximized size, then restore but at maximum size
  564.          GetWindowRect(hwnd,rect);
  565.          ShowWindow(hwnd,ForeGround ? SW_RESTORE : SW_RESTORENOACTIVE);
  566.          SetWindowRect(hwnd,rect);
  567.       }
  568.    }
  569.    if ( Minimized )
  570.       ShowWindow(hwnd,ForeGround ? SW_SHOWMINIMIZED : SW_SHOWMINNOACTIVE);
  571.    if ( ForeGround )
  572.       SetActiveWindow(hwnd);
  573.    if ( WantSetSize ) {
  574.       if ( WantSetPosition )
  575.          SetWindowPos(hwnd,0,PosX,PosY,SizeX,SizeY,SWP_SIZE | SWP_MOVE);
  576.       else
  577.          SetSize(hwnd,SizeX,SizeY);
  578.    } else if ( WantSetPosition )
  579.       SetPosition(hwnd,PosX,PosY);
  580.    if ( Hidden )
  581.       ShowWindow(hwnd,SW_HIDE);
  582. }
  583.  
  584. Instructions()
  585. {
  586.    printf("\n")
  587.    printf("Session - Start a session\n")
  588.    printf("\n")
  589.    printf("SYNTAX: Session [Options] Command [Command arguments...]\n")
  590.    printf("\n")
  591.    printf("Options: /F - Start session in the foreground\n")
  592.    printf("         /B - Start session in the background\n")
  593.    printf("         /TITLE \"Program Title\" - Session Title\n")
  594.    printf("            For Windows sessions this is title windows will give\n")
  595.    printf("         /I - Inherit environment of CONFIG.SYS, not current settings\n")
  596.    printf("         /FS - Full-Screen DOS, OS/2, or Windows session\n")
  597.    printf("         /WIN - Windowed DOS, OS/2, or Windows session\n")
  598.    printf("         /PM - Presentation Manager application\n")
  599.    printf("         /DOS - DOS application\n")
  600.    printf("         /W - Windows application\n")
  601.    printf("         /SEP - Separate Windows session (for /W)\n")
  602.    printf("                Always Searate sessions in this version\n")
  603.    printf("         /ENH - Enhanced-mode Windows session\n")
  604.    printf("         /ICON FileSpec - Full name of an Icon file\n")
  605.    printf("         /HID - Window initially hidden\n")
  606.    printf("         /MAX - Initially maximized\n")
  607.    printf("         /MIN - Initially minimized\n")
  608.    printf("         /BIG - Not maximized, but at maximum size\n")
  609.    printf("         /K - Keep Windowed session open after program completes\n")
  610.    printf("         /WAIT - Wait until session ends\n")
  611.    printf("         /POS X,Y - Set the X and Y position\n")
  612.    printf("         /SIZE X,Y - Set the width (X) and height (Y) of session\n")
  613.    printf("         /FONT YxX - Set Height (Y) and Width (X) of DOS or OS/2 windowed font\n")
  614.    printf("         /SET SET=VALUE - Dos Settings, any number of these allowed\n")
  615.    printf("         /SET @FileSpec - Get DOS settings from FileSpec, except blank and ';' lines\n")
  616.    printf("         /SET #ENVVAR - Get DOS settings from environment variable <ENVVAR>\n")
  617.    printf("              where values in NAME,VAL;NAME,VAL format\n")
  618.    printf("\n")
  619.    printf("NOTE: SESSION.CMD contains a list of default DOS settings.  You may want to\n")
  620.    printf("      alter these by editing SESSION.CMD and change MyDefaultDOSSettings\n")
  621.    printf("      DOS settings are only specified for session if the /DOS, /W, or /SET\n")
  622.    printf("\n")
  623.    printf("      If command arguments take any of the same flags as SESSION.CMD then you\n")
  624.    printf("      May want to include those in quotes and with spaces.  For example:\n")
  625.    printf("          SESSION /WIN CMD.EXE \"/K mode 80,50\"\n")
  626. }
  627.  
  628.